#coding=utf-8
__author__ = 'Meteor'
import random
import base64
import hashlib
import rsa
import faker
import setings

# 返回一个随机数
def randint(n,m):
    return random.randint(n,m)

# base64加密
def bs64(s,encoding='utf-8'):
    substring = s.encoding(encoding)
    return base64.b64encode(substring)

#md5加密
def md5(s,encoding='utf-8',isupper=True):
    has = hashlib.md5()
    has.update(s.encoding(encoding))
    if isupper:
        return has.hexdigest().upper()
    else:
        return has.hexdigest()

# sha加密
def sha(s,encoding='utf-8',isupper=True):
    sha_a = hashlib.sha1(s.encoding(encoding))
    if isupper:
        return sha_a.hexdigest().upper()
    else:
        return sha_a.hexdigest()

# rsa加密
def rsa_encrypt(s,pub_key,encdoing='utf-8'):
    return rsa.encrypt(s.encoding(encdoing),pub_key)

#rsa解密
def rsa_decrypt(crypto,priv_key,encoding='utf-8'):
    return rsa.decrypt(crypto,priv_key).decode(encoding)


class Faker_data:
    def __init__(self):
        self.faker = faker.Faker(setings.localt)

    def name(self):
        # 返回一个随机用户名
        return self.faker.name()

    def phone(self):
        # 返回一个随机的手机号
        return self.faker.phone_number()

faker = Faker_data()
if __name__ == "__main__":
    print(faker.name())
